from typing import Union, Tuple, Any
import threading


class ThreadSafeObject:
    def __init__(self, key: Union[str, Tuple], obj: Any = None, pool: "CachePool" = None):
        self._obj = obj
        self._key = key
        self._pool = pool
        self._lock = threading.RLock()
        self._loaded = threading.Event()

    def __repr__(self) -> str:
        cls = type(self).__name__
        return f"<{cls}: key: {self.key}, obj: {self._obj}>"

    @property
    def key(self):
        return self._key

    @property
    def obj(self):
        return self._obj

    @obj.setter
    def obj(self, val: Any):
        self._obj = val


if __name__ == '__main__':

    ths_obj = ThreadSafeObject('key01', 'Object_str')
    print('type(ths_obj)', type(ths_obj))
    print('type(ths_obj).__name__', type(ths_obj).__name__)
    print('ths_obj', ths_obj)
    print('ths_obj.key', ths_obj.key)
    print('ths_obj.obj', ths_obj.obj)

    print('Setting ...')
    ths_obj.obj = 'Obj_str_002'
    print('ths_obj.key', ths_obj.key)
    print('ths_obj.obj', ths_obj.obj)